package com.alibaba.middleware.hsf.guide.registry;

import com.taobao.hsf.annotation.Order;
import com.taobao.hsf.annotation.Scope;
import com.taobao.hsf.model.metadata.ServiceMetadata;
import com.taobao.hsf.protocol.Protocol;
import com.taobao.hsf.registry.AbstractRawAddressListenerInterceptor;
import com.taobao.hsf.registry.Registry;

import org.apache.commons.lang.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * @author weipeng2k 2017年11月06日 下午13:40:11
 */
@Order(100)
@Scope(Scope.Option.PROTOTYPE)
public class RawAddressListenerDemo extends AbstractRawAddressListenerInterceptor {
    @Override
    public void notify(Registry registry, Protocol protocol, ServiceMetadata serviceMetadata, List<String> addresses) {
        StringBuilder sb = new StringBuilder();
        sb.append(new Date()).append("@RawAddressListenerDemo##").append("\n");
        sb.append("Registry: ").append(registry.getClass().getName()).append("\n");
        sb.append(", accept: ").append(StringUtils.join(addresses.toArray(new String[]{}))).append("\n");
        sb.append(" for Protocol: ").append(protocol.getClass().getName()).append("\n");
        sb.append(" on Service: ").append(serviceMetadata.getUniqueName()).append("\n");
        sb.append(" in Thread:").append(Thread.currentThread());
        System.out.println(sb.toString());

        next.notify(registry, protocol, serviceMetadata, addresses);
    }
}
